package com.gxc.string;

import java.lang.*;

/**
 * 2710. 移除字符串中的尾随零
 * 给你一个用字符串表示的正整数 num ，请你以字符串形式返回不含尾随零的整数 num
 */
public class RemoveTrailingZeros {

    public static void main(String[] args) {
        System.out.println(handle("51230100"));
        System.out.println(handle("123"));
    }

    public static String handle(String num) {
        int n = num.length()-1;
        for (; n >= 0; n--) {
            if (num.charAt(n) == '0') {

            } else {
                break;
            }
        }
        return num.substring(0, n+1);
    }

    class Solution {
        public String removeTrailingZeros(String num) {
            int len = num.length();
            while (len > 0 && num.charAt(len - 1) == '0') {
                len--;
            }
            return num.substring(0, len);
        }
    }

}
